home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / UNIX-LPR.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1993-05-07  |  4KB  |  151 lines

  1. #!/bin/sh
  2. #
  3. # Unix lpr filter. The default setup sends output directly to a pipe,
  4. # which requires the Ghostscript process to fork, and thus may cause 
  5. # small systems to run out of memory/swap space. An alternative strategy,
  6. # based on a suggestion by Andy Fyfe (andy@cs.caltech.edu), uses a named
  7. # pipe for output, which avoids the fork and can thus save a lot of memory.
  8. #
  9. # Unfortunately this approach can cause problems when a print job is aborted, 
  10. # as the abort can cause one of the processes to die, leaving the process 
  11. # at the other end of the pipe hanging forever.
  12. #
  13. # Because of this, the named pipe method has not been made the default,
  14. # but it may be restored by commenting out the lines referring to
  15. # 'gsoutput' and uncommenting the lines referring to 'gspipe'.
  16. #
  17.  
  18. PBMPLUSPATH=/usr/local/pbmplus/bin
  19. PSFILTERPATH=/usr/local/tran/sparc/lib
  20. LOCALPATH=/usr/local/bin
  21. X11HOME=/usr/local/X11R5
  22.  
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/etc
  24. PATH=${PATH}\:${LOCALPATH}\:${PBMPLUSPATH}\:${PSFILTERPATH}
  25. LD_LIBRARY_PATH=${X11HOME}/lib
  26.  
  27. export PATH LD_LIBRARY_PATH acctfile host user
  28.  
  29. user= host= acctfile=/dev/null
  30.  
  31. #
  32. # Redirect stdout to stderr (for the logfile) and open a new channel
  33. # connected to stdout for the raw data. This enables us to keep the
  34. # raw data separate from programmed postscript output and error messages.
  35. #
  36. exec 3>&1 1>&2
  37.  
  38. #
  39. # Get username and hostname from filter parameters
  40. #
  41. while [ $# != 0 ]
  42. do  case "$1" in
  43.   -n)    user=$2 ; shift ;;
  44.   -h)    host=$2 ; shift ;;
  45.   -*)    ;;
  46.   *)    acctfile=$1 ;;
  47.   esac
  48.   shift
  49. done
  50.  
  51. #
  52. # Get the filter, printer device and queue type (direct/indirect)
  53. #
  54. filter=`basename $0`
  55. device=`dirname $0`
  56. type=`dirname ${device}`
  57. device=`basename ${device}`
  58. type=`basename ${type}`
  59.  
  60. #
  61. # Find the bpp, if specified
  62. #
  63. case "${device}" in
  64.   *.24) device=`basename ${device} .24` ; bpp=24 ;;
  65.   *.16) device=`basename ${device} .16` ; bpp=16 ;;
  66.   *.8)  device=`basename ${device} .8`  ; bpp=8  ;;
  67.   *.3)  device=`basename ${device} .3`  ; bpp=3  ;;
  68.   *.1)  device=`basename ${device} .1`  ; bpp=1  ;;
  69.   *)    bpp=1 ;;
  70. esac
  71.  
  72. #
  73. # Information for the logfile
  74. #
  75. lock=`dirname ${acctfile}`/lock
  76. cf=`tail -1 ${lock}`
  77. job=`egrep '^J' ${cf} | tail +2c`
  78.  
  79. echo "gsbanner: ${host}:${user}  Job: ${job}  Date: `date`"
  80. echo "gsif: ${host}:${user} ${device}.${bpp} start - `date`"
  81.  
  82. #
  83. # Set the direct or indirect output destinations
  84. #
  85. #gspipe=/tmp/gspipe.$$
  86. #mknod ${gspipe} p
  87.  
  88. case "${type}" in
  89.   direct)
  90.         gsoutput="cat 1>&3" ;;
  91. #        cat ${gspipe} 1>&3 & ;;
  92.   indirect)
  93.         gsoutput="lpr -P${device}.raw" ;;
  94. #        cat ${gspipe} | lpr -P${device}.raw & ;;
  95. esac
  96.  
  97. (
  98. #
  99. # Any setup required may be done here (eg. setting gamma for colour printing)
  100. #
  101. echo "{0.333 exp} dup dup currenttransfer setcolortransfer"
  102.  
  103. #
  104. # The input data is filtered here, before being passed on to Ghostscript
  105. #
  106. case "${filter}" in
  107.   gsif)      cat ;;
  108.   gsnf)      psdit ;;
  109.   gstf)      pscat ;;
  110.   gsgf)      psplot ;;
  111.   gsvf)      rasttopnm | pnmtops ;;
  112.   gsdf)      dvi2ps -sqlw ;;
  113.   gscf|gsrf) echo "${filter}: filter not available" 1>&2 ; exit 0 ;;
  114. esac
  115.  
  116. #
  117. # This is the postlude which does the accounting
  118. #
  119. echo "\
  120. (acctfile) getenv
  121.   { currentdevice /PageCount gsgetdeviceprop dup cvi 0 gt
  122.     { exch (a) file /acctfile exch def
  123.       /string 20 string def
  124.       string cvs dup length dup
  125.       4 lt
  126.         { 4 exch sub
  127.           { acctfile ( ) writestring } repeat
  128.         } { pop } ifelse
  129.       acctfile exch writestring
  130.       acctfile (.00 ) writestring
  131.       acctfile (host) getenv 
  132.         { string cvs } { (NOHOST) } ifelse writestring
  133.       acctfile (:) writestring
  134.       acctfile (user) getenv
  135.         { string cvs } { (NOUSER) } ifelse writestring
  136.       acctfile (\n) writestring
  137.       acctfile closefile
  138.     } { pop } ifelse
  139.   } if
  140. quit"
  141. ) | gs -q -dNOPAUSE -sDEVICE=${device} -dBitsPerPixel=${bpp} \
  142.         -sOutputFile=\|"${gsoutput}" -
  143. #        -sOutputFile=${gspipe} -
  144.  
  145. rm -f ${gspipe}
  146. #
  147. # End the logfile entry
  148. #
  149. echo "gsif: end - `date`"
  150.  
  151.